#include <stdio.h>
#include <stdlib.h>

#define N_MAX 20
#define M_MAX 20

int
main(void)
{
	int map[N_MAX][M_MAX], n = 0, m = 0, x = 0, hod = 0;
	int i = 0, j = 0;
	int profit = 0;

	freopen("gold.in", "r", stdin);
	freopen("gold.out","w",stdout);

	scanf("%d%d", &n, &m);
	for (i = 0 ; i < n ; ++i)
		for (j = 0 ; j < m ; ++j)
			scanf("%d", &map[i][j]);

	i = j = 0; /* i - rows ; j - columns */
	scanf("%d", &x);
	profit = map[i][j];
	map[i][j] = 0;
	while (--x > 0) {
		scanf("%d", &hod);
		switch (hod) {
			case 1: ++j; break;
			case 2: --i; break;
			case 3: --j; break;
			case 4: ++i; break;
		}

		profit += map[i][j];
		map[i][j] = 0;
	}
	printf("%d\n", profit);
}
